import requestApi from '../requestApi'
import { toast } from 'nc-lightapp-front';

export default function searchClick(props, searchVal) {
    if(true){
        let bxdata = window.invoiceListQueryParam;
        let data={
            querycondition:searchVal==null?{}:searchVal,
            pagecode: window.invoicePageCode.searchPage,
            pageInfo:{
                "pageIndex":-1,
                "pageSize":10,
                "totalPage":"0"
            },
            queryAreaCode:window.InvoiceWalletAreaCode.searchArea,  //查询区编码
            oid:props.meta.getMeta()[window.InvoiceWalletAreaCode.searchArea].oid,  ////pub_area 中PK_AREA
            querytype:'tree'
        };
        let senddata = { bxdata, data, pagecode: window.invoicePageCode.searchPage, tepmid:this.props.meta.getMeta().pageid};

        //add 过滤关联表体的发票
        const { getCardData } = props;
        const tableData = getCardData() || [];
        const selectedInvoiceList = [];
        for (let row of tableData) {
            if (row && row.values && row.values.pk_erminvoice) {
              selectedInvoiceList.push({
                pk_erminvoice: row.values.pk_erminvoice.value,
                generatetype: row.values.generatetype && row.values.generatetype.value,
              });
            }
        }
        senddata.selectedData = selectedInvoiceList;

        requestApi.query({
            data:senddata,
            success: (data) => {
                //先取消勾选
                this.props.transferTable.cancelRowsChecked(
                    "head",
                    Object.keys(this.deleteList)
                );
                this.deleteList = {};

                if(data){
                    this.setTransferBtnDisabled(false);
                    data.forEach(item => {
                        if(!item.body) {
                            item.body = {body: {areacode: 'body', rows: []}}
                        }
                    })
                    this.invoiceList = data;
                    data && this.props.transferTable.setTransferTableValue(window.InvoiceWalletAreaCode.billsArea, window.InvoiceWalletAreaCode.bodysArea, data, 'pk_erminvoice', 'pk_erminvoice_b');
                } else {
                    this.props.transferTable.setTransferTableValue(window.InvoiceWalletAreaCode.billsArea, window.InvoiceWalletAreaCode.bodysArea, [], 'pk_erminvoice', 'pk_erminvoice_b');
                    toast({ content: '未查询到发票', color: 'warning' });
                }

            }
        })
    }
}

